package com.sungrowpower.kit.customview;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

public class RounderAndCircleAvatarView extends RelativeLayout {
    //头像宽度
    private int mAvatarWidth;
    //头像的高度
    private int mAvatarHeight;
    //头像的src
    private Drawable mAvaterSrc;
    //头像形状 圆形 true 非圆 false
    private boolean mAvatarOver;
    //头像边框的宽
    private float mAvaterBorderWidth;
    //圆形头像的半径
    private int mAvaterRadius;
    //头像边框的颜色
    private int avaterBorderColor;
    //头像的背景颜色
    private int mAvaterBackgroundColor;
    //头像底部文字是不是要显示
    private boolean bottomTextShow;
    //头像底部文字内容
    private String avaterTextBottom;
    //头像底部文字的颜色
    private int avaterTextBottomColor;
    //头像底部文字的大小
    private int avaterTextBottomSize;
    //自定义头像
    private RoundedImageView roundedImageView;
    //底部头像的内容
    private TextView tv_bottom_content;
    //头像中间的问题
    private String avaterTextCenter;
    //头像中间的颜色
    private int avaterTextCenterColor;
    //头像中间文字的大小
    private int avaterTextCenterSize;
    //头像中间文字加粗
    private boolean avaterCenterBold;
    //头像中间的文字要不要显示
    private boolean avaterCenterTextShow;
    //头像文字内容
    private TextView tv_center_content;
    //多个图片 画头像圆的半径
    private int mRadius;
    //多个头像头像的个数
    private int avaterCount;
    //是否显示多个头像
    private boolean avaterMinux;
    //多个头像的覆盖间距
    private float avaterSpace;
    //多个头像是否先完成第一个被添加
    private boolean mIsLastComplete;
    private Context context;

    //多个图的文字内容
    private List<String> words = new ArrayList<>();
    //对个图片的背景颜色
    private List<Integer> backgrounds = new ArrayList<>();
    //是否显示右边小图标
    private boolean isShowRightIcom;
    //右边小图标的宽
    private int rightIcomWidth;
    //右边小图标的高
    private int rightIcomHeight;
    //右边小图标的背景颜色
    private int rightIcomBackgroundColor;
    //是否显示右边的标题
    private boolean isShowRightTitle;
    //设置右边标题的内容
    private String rightTitleWord;
    //设置右边标题的颜色
    private int rightTitleColor;
    //设置右边标题的字体大小
    private int rightTitleSize;
    //设置右边文本的内容
    private String rightContentWord;
    //设置右边文本的颜色
    private int rightContentColor;
    //设置右边文本的颜色
    private int rightContentSize;
    //设置右边文本到顶部的大小
    private int rightContentTopSize;
    //右边的标题
    private TextView tv_user_title;
    //右边的内容
    private TextView tv_user_content;
    private RoundedImageView riv_icon_imageview;
    private onClickListener listener;

    private HashMap<View, Integer> hashMap = new HashMap<>();


    public RounderAndCircleAvatarView(Context context) {
        this(context, null);
    }

    public RounderAndCircleAvatarView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public RounderAndCircleAvatarView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        initTypedArray(context, attrs);
        initView(context);
    }

    private void initView(Context context) {
        this.context = context;
        this.mInflater = LayoutInflater.from(context);
        View view = LayoutInflater.from(context).inflate(R.layout.avatar_layout, this, true);
        roundedImageView = view.findViewById(R.id.riv_imageview);

        Log.i("tinatianqin", "initTypedArray:   avaterMinux=" + avaterMinux + "hashcode=" + hashCode());

        //判断是不是多个图片
        if (avaterMinux) {
            backgrounds.add(R.color.color_5CC900);
            backgrounds.add(R.color.color_00CDC7);
            backgrounds.add(R.color.color_ff7d00);
            backgrounds.add(R.color.color_ff7d00);
            backgrounds.add(R.color.color_bebebe);

            Collections.reverse(backgrounds);

            words.add("Nietsiche");
            words.add("M");
            words.add("X");
            words.add("Z");
            if (avaterCount > 5) {
                words.add("+" + (avaterCount - 5));
            } else {
                words.add(avaterCount + "");
            }

            Collections.reverse(words);

            initDatas(avaterCount, words, backgrounds);
        } else {
            // ("非多张图");
            LayoutParams layoutParams = (LayoutParams) roundedImageView.getLayoutParams();
            layoutParams.width = mAvatarWidth;
            layoutParams.height = mAvatarHeight;
            roundedImageView.setLayoutParams(layoutParams);
            //设置头像
            roundedImageView.setImageDrawable(mAvaterSrc);
            //设置背景颜色
            roundedImageView.setBackgroundColor(mAvaterBackgroundColor);

            tv_bottom_content = view.findViewById(R.id.tv_bottom_content);
            tv_center_content = view.findViewById(R.id.tv_center_content);
            //判断是圆和方
            if (mAvatarOver) {
                roundedImageView.setOval(true);
                roundedImageView.setBorderColor(avaterBorderColor);
                //显示底部的内容
                if (bottomTextShow) {
                    tv_bottom_content.setVisibility(VISIBLE);
                    tv_bottom_content.setText(avaterTextBottom);
                    tv_bottom_content.setTextSize(avaterTextBottomSize);
                    tv_bottom_content.setTextColor(avaterTextBottomColor);

                } else {
                    tv_bottom_content.setVisibility(GONE);
                }


            } else {
                roundedImageView.setOval(false);
                //设置圆角宽度 和 大小 和 颜色
                roundedImageView.setBorderWidth(mAvaterBorderWidth);
                roundedImageView.setBorderColor(avaterBorderColor);
//            //设置圆角
                roundedImageView.setCornerRadius(mAvaterRadius, mAvaterRadius, mAvaterRadius, mAvaterRadius);
            }

            if (avaterCenterTextShow) {
                //显示中间的文本内容
                tv_center_content.setVisibility(VISIBLE);
                tv_center_content.setText(avaterTextCenter);
                tv_center_content.setTextSize(avaterTextCenterSize);
                tv_center_content.setTextColor(avaterTextCenterColor);
                //字体是不是加粗
                if (avaterCenterBold) {
                    tv_center_content.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                } else {
                    tv_center_content.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
                }
            } else {
                tv_center_content.setVisibility(GONE);
            }
            //判断是不是要显示头像右边的小图标
            if (isShowRightIcom) {
                RoundedImageView riv_item_right_imageview = view.findViewById(R.id.riv_imageview);
                riv_item_right_imageview.setVisibility(GONE);
                RoundedImageView riv_item_right_imageview_two = view.findViewById(R.id.riv_imageview_two);
                riv_item_right_imageview_two.setVisibility(VISIBLE);
                riv_icon_imageview = view.findViewById(R.id.riv_icon_imageview);
                riv_icon_imageview.setVisibility(VISIBLE);
                LayoutParams layoutParams1 = (LayoutParams) riv_item_right_imageview_two.getLayoutParams();
                layoutParams1.width = mAvatarWidth;
                layoutParams1.height = mAvatarHeight;
                riv_item_right_imageview_two.setLayoutParams(layoutParams1);

                LayoutParams layoutParams2 = (LayoutParams) riv_icon_imageview.getLayoutParams();
                layoutParams2.width = rightIcomWidth;
                layoutParams2.height = rightIcomHeight;
                layoutParams2.leftMargin = mAvatarWidth / 2;
                riv_icon_imageview.setLayoutParams(layoutParams2);
                riv_icon_imageview.setBackgroundColor(rightIcomBackgroundColor);


            }
            //设置头像右边标题是不是显示
            LinearLayout ll_title_content = view.findViewById(R.id.ll_title_content);
            if (isShowRightTitle) {
                ll_title_content.setVisibility(VISIBLE);
                tv_user_title = view.findViewById(R.id.tv_user_name);
                tv_user_content = view.findViewById(R.id.tv_user_content);
                tv_user_title.setText(rightTitleWord);
                tv_user_title.setTextSize(rightTitleSize);
                tv_user_title.setTextColor(rightTitleColor);

                tv_user_content.setText(rightContentWord);
                tv_user_content.setTextColor(rightContentColor);
                tv_user_content.setTextSize(rightContentSize);
                LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) tv_user_content.getLayoutParams();
                layoutParams1.topMargin = rightContentTopSize;
                tv_user_content.setLayoutParams(layoutParams1);

            } else {
                ll_title_content.setVisibility(GONE);
            }


        }

        setOnClickListener(v -> {

            Log.i("tinatianqin", "initTypedArray:   avaterMinux=" + avaterMinux + "hashcode=" + hashCode());
            if (mAvatarOver) {
                //判断是不是中间有文字的头像
                if (avaterCenterTextShow) {
                    Toast.makeText(context, "点击了字体圆形头像,字体=" + avaterTextCenter, Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(context, "点击了圆形头像", Toast.LENGTH_SHORT).show();
                }
            } else {
                if (avaterCenterTextShow) {
                    Toast.makeText(context, "点击了字体方形头像,字体=" + avaterTextCenter, Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(context, "点击了方形头像", Toast.LENGTH_SHORT).show();
                }

            }
        });

    }

    private void initTypedArray(Context context, AttributeSet attrs) {

        AvatarItemBean avatarItem = new AvatarItemBean();

        TypedArray mTypedArray = context.obtainStyledAttributes(attrs, R.styleable.SGRonderAndCircleAvatarView);
        //头像的宽
        float avatarWidth = mTypedArray.getDimension(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_width,
                avatarItem.getAvatarWidth());
        mAvatarWidth = DensityUtil.dip2px(context, avatarWidth);
        //头像的高
        float avatarHeight = mTypedArray.getDimension(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_height,
                avatarItem.getAvatarHeight());

        mAvatarHeight = DensityUtil.dip2px(context, avatarHeight);
        //头像的src
        mAvaterSrc = mTypedArray.getDrawable(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_src);
        //判断是圆还是方
        mAvatarOver = mTypedArray.getBoolean(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_overlay, avatarItem.isOver());

        //设置圆角宽度
        mAvaterBorderWidth = mTypedArray.getDimension(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_border_width,
                avatarItem.getAvatarBorderWidth());

        //设置圆角大小
        mAvaterRadius = (int) mTypedArray.getDimension(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_Radius_size,
                avatarItem.getAvatarRadiusSize());

        //设置圆角背景
        avaterBorderColor = mTypedArray.getColor(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_border_color,
                getResources().getColor(R.color.color_bebebe));
        //设置头像背景
        mAvaterBackgroundColor = mTypedArray.getColor(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_background_color,
                avatarItem.getAvatarBackgroundColor());
        //获取是不是显示底部头像的文本
        bottomTextShow = mTypedArray.getBoolean(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_bottom_text_show,
                avatarItem.isAvatarBottomTextShow());
        //获取底部文本的内容
        avaterTextBottom = mTypedArray.getString(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_bottom_text);
        //获取底部文本的颜色
        avaterTextBottomColor = mTypedArray.getColor(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_bottom_text_color,
                getResources().getColor(R.color.color_bebebe));
        //获取底部文本的大小
        avaterTextBottomSize = (int) mTypedArray.getDimension(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_bottom_text_size,
                avatarItem.getAvatarBottomTextSize());

        //获取显示中间文本的内容
        avaterCenterTextShow = mTypedArray.getBoolean(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_center_show, false);
        //获取中间文本的内容
        avaterTextCenter = mTypedArray.getString(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_center_text);
        //获取中间文本的颜色
        avaterTextCenterColor = mTypedArray.getColor(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_center_text_color,
                getResources().getColor(R.color.color_bebebe));
        //获取中间文本的大小
        avaterTextCenterSize = (int) mTypedArray.getDimension(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_center_text_size,
                avatarItem.getAvatarCenterTextSize());
        //获取中间文字加粗
        avaterCenterBold = mTypedArray.getBoolean(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_center_text_bold,
                avatarItem.isCenterBold());
        //多个图圆的半径
        float avaterRadius = mTypedArray.getFloat(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_radius, 13);

        mRadius = DensityUtil.dip2px(context, avaterRadius);
        //图片最多的个数
        avaterCount = (int) mTypedArray.getInteger(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_maxCount,
                avatarItem.getmMaxCount());
        //是否显示不多图片
        avaterMinux = mTypedArray.getBoolean(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_minux, avatarItem.isShowRightIcom());

        //获取覆盖的百分比
        avaterSpace = mTypedArray.getFloat(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_space, avatarItem.getmSpace());
        //判断 是不是最后完成
        mIsLastComplete = mTypedArray.getBoolean(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_isLastComplete, avatarItem.ismIsLastComplete());

        //判断要不要显示右边的图标
        isShowRightIcom = mTypedArray.getBoolean(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_right_icom_show,
                avatarItem.isAvatarBottomTextShow());


        //设置右边小图标的宽
        rightIcomWidth = (int) mTypedArray.getDimension(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_right_icom_width, avatarItem.getRightIcomWidth());
        //设置右边小图标的高
        rightIcomHeight = (int) mTypedArray.getDimension(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_right_icom_height,
                avatarItem.getRightIcomHeight());
        //设置小图标的背景
        rightIcomBackgroundColor = mTypedArray.getColor(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_right_icom_background_color,
                avatarItem.getRightIcomBackgroundColor());
        //设置头像右边标题是不是显示
        isShowRightTitle = mTypedArray.getBoolean(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_content_show,
                avatarItem.isShowRightIcom());
        //设置头像右边标题的名称
        rightTitleWord = mTypedArray.getString(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_title_word);
        //设置头像右边标题的颜色
        rightTitleColor = mTypedArray.getColor(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_title_color,
                getResources().getColor(R.color.color_bebebe));
        //设置头像右边标题的大小
        rightTitleSize = (int) mTypedArray.getDimension(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_title_size,
                avatarItem.getAvatarCenterTextSize());
        //设置头像右边内容的名称
        rightContentWord = mTypedArray.getString(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_content_word);
        //设置头像右边内容的颜色
        rightContentColor = mTypedArray.getColor(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_content_color,
                getResources().getColor(R.color.color_bebebe));
        //设置头像右边内容的大小
        rightContentSize = (int) mTypedArray.getDimension(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_content_size,
                avatarItem.getAvatarCenterTextSize());
        //设置头像右边到顶部的距离
        rightContentTopSize = (int) mTypedArray.getDimension(R.styleable.SGRonderAndCircleAvatarView_sgkit_racav_avater_margin_top_size, avatarItem.getAvatarBottomTextSize());
    }

    /**
     * 头像间的距离
     */

    private Context mContext;
    private LayoutInflater mInflater;


//    @Override
//    public boolean dispatchTouchEvent(MotionEvent ev) {
//        if (avaterMinux){
//            return super.dispatchTouchEvent(ev);
//        }else {
//            //头像的点击事件
//
//        }
//        return super.dispatchTouchEvent(ev);
//    }
//    @Override
//    public boolean onTouchEvent(MotionEvent event){
//        if (avaterMinux){
//            return true;
//        }
//        return super.onTouchEvent(event);
//    }


    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        //如果不是多个图片
        if (!avaterMinux) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            return;
        }

        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int heiMeasure = MeasureSpec.getSize(heightMeasureSpec);
        int heiMode = MeasureSpec.getMode(heightMeasureSpec);
        int widMode = MeasureSpec.getMode(widthMeasureSpec);
        int widMeasure = MeasureSpec.getSize(widthMeasureSpec);

        int wid = 0;
        int hei = 0;
        int count = getChildCount();
        for (int i = 0; i < count; i++) {
            View child = getChildAt(i);
            LayoutParams lp = (LayoutParams) child.getLayoutParams();
            lp.width = 2 * mRadius;
            lp.height = lp.width;
            child.setLayoutParams(lp);
            // 测量子View的宽和高,系统提供的measureChild
            measureChild(child, widthMeasureSpec, heightMeasureSpec);
            // 子View占据的宽度
            int childWidth = child.getMeasuredWidth();
            // 子View占据的高度
            int childHeight = child.getMeasuredHeight();

            if (i < avaterCount) {
                if (i == 0) {
                    wid = wid + childWidth;
                } else {
                    wid = (int) (wid + childWidth * avaterSpace);
                }
            }
            hei = Math.max(hei, childHeight);
        }
        //如果是exactly使用测量宽和高，否则使用自己设置的宽和高
        setMeasuredDimension((widMode == MeasureSpec.EXACTLY) ? widMeasure : wid,
                (heiMode == MeasureSpec.EXACTLY) ? heiMeasure : hei);
    }


    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        if (!avaterMinux) {
            super.onLayout(changed, l, t, r, b);
            return;
        }

        int count = getChildCount();

        int left = 0;
        int top = 0;
        int right = 0;
        for (int i = 0; i < count; i++) {
            View child;
            if (mIsLastComplete) {
                child = getChildAt(i);
            } else {
                //获取的是最后一个子view 在测试的时候就已经设置好了最后一个子view 的left  和 right 位置
                child = getChildAt(count - i - 1);
            }
            int childWidth = child.getMeasuredWidth();
            int childHeight = child.getMeasuredHeight();

            if (i == 0) {
                //把最后一个view放在第一个位置 ，第一个view 放在最后的位置 ，其实在添加的时候还是按照循序添加的
                right = right + childWidth;
            } else {
                right = (int) (right + childWidth * avaterSpace);
            }
            child.layout(left, top, right, childHeight);
            left = (int) (left + childWidth * avaterSpace);
        }
    }

    /**
     * 初始化数据
     *
     * @param list
     * @param words
     * @param backgrounds
     */
    public void initDatas(int list, List<String> words, List<Integer> backgrounds) {
        if (list == 0) {
            return;
        }
        removeAllViews();
        if (list >= 5) {
            list = 5;
        }

        avaterCount = list;
        for (int i = 0; i < list; i++) {
            View view = mInflater.inflate(R.layout.avatar, this, false);
            RoundedImageView iv = view.findViewById(R.id.iv);
            TextView tv = view.findViewById(R.id.tv);
            tv.setText(words.get(i));

            iv.setBackgroundColor(context.getResources().getColor(backgrounds.get(i)));

            int finalI = i;
            view.setOnClickListener(v -> {
                Log.i("", "initDatas: ");

                Toast.makeText(context,
                        "点击了多个图片,内容=" + words.get(finalI), Toast.LENGTH_LONG).show();
            });

            this.addView(view);
            // view.getParent().requestDisallowInterceptTouchEvent(true);
        }

    }


    public RoundedImageView getAverageImageView() {
        return roundedImageView;
    }

    public void setDataBean(AvatarItemBean avatarItem) {
        //设置是圆还是方的获取
        roundedImageView.setOval(avatarItem.isOver());
        //设置图片的地址
        roundedImageView.setImageResource(avatarItem.getSrc());
        //设置图片头像的宽
        LayoutParams layoutParams = (LayoutParams) roundedImageView.getLayoutParams();
        layoutParams.width = avatarItem.getAvatarWidth();
        layoutParams.height = avatarItem.getAvatarHeight();
        roundedImageView.setLayoutParams(layoutParams);
        //设置头像背景
        roundedImageView.setBackgroundColor(avatarItem.getAvatarBackgroundColor());
        //设置变宽的颜色
        roundedImageView.setBorderColor(avatarItem.getAvatarBorderBackgroundColor());
        //设置边框的宽度
        roundedImageView.setBorderWidth(avatarItem.getAvatarBorderWidth());
        //设置边框中间的文字
        tv_center_content.setText(avatarItem.getAvatarCenterName());
        //设置中间文字的颜色
        tv_center_content.setTextSize(avatarItem.getAvatarContentColor());
        //设置中间文字的大小
        tv_center_content.setTextColor(avatarItem.getAvatarContentSize());
        //设置中间文字的字体加粗
        if (avatarItem.isCenterBold()) {
            tv_center_content.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        } else {
            tv_center_content.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        }
        //设置头像底部字体的名称
        tv_bottom_content.setText(avatarItem.getAvatarBottomName());
        //设置头像底部字体的颜色
        tv_bottom_content.setTextColor(avatarItem.getAvatarBottomTextColor());
        //设置底部字体的大小
        tv_bottom_content.setTextSize(avatarItem.getAvatarBottomTextSize());
        //方形圆角的大小
        roundedImageView.setCornerRadius(avatarItem.getAvatarRadiusSize());
        //头像标题文本颜色
        tv_user_title.setTextColor(avatarItem.getAvatarTitleColor());
        //头像标题文本的内容
        tv_user_title.setText(avatarItem.getAvatarTitleWord());
        //头像标题文本的大小
        tv_user_title.setTextSize(avatarItem.getAvatarTitleSize());
        //头像内容右边文本的颜色
        tv_user_content.setTextColor(avatarItem.getAvatarContentColor());
        //设置头像右边文本的内容
        tv_user_content.setText(avatarItem.getAvatarContentWord());
        //设置右边文字的大小
        tv_user_content.setTextSize(avatarItem.getAvatarCenterTextSize());
        //头像内容到文本到顶部的距离
        LayoutParams layoutParams1 = (LayoutParams) tv_user_content.getLayoutParams();
        layoutParams1.topMargin = avatarItem.getAvatarMarginTopSize();
        tv_user_content.setLayoutParams(layoutParams1);
        //设置右边小图标的宽
        ViewGroup.LayoutParams layoutParams2 = riv_icon_imageview.getLayoutParams();
        layoutParams2.width = avatarItem.getAvatarIconWidth();
        layoutParams2.height = avatarItem.getAvatarHeight();
        riv_icon_imageview.setLayoutParams(layoutParams2);
        //奢姿最右边小图标的背景颜色
        riv_icon_imageview.setBackgroundColor(avatarItem.getRightIcomBackgroundColor());

        invalidate();
    }

    //奢姿最右边小图标的背景颜色
    public RounderAndCircleAvatarView setRightIcomBackgroundColor(int color) {
        if (riv_icon_imageview != null) {
            riv_icon_imageview.setBackgroundColor(color);
        }
        return this;
    }

    //设置右边小图标的宽
    public RounderAndCircleAvatarView setShowRightSmallIconWidth(int width) {
        if (riv_icon_imageview != null) {
            ViewGroup.LayoutParams layoutParams2 = riv_icon_imageview.getLayoutParams();
            layoutParams2.width = width;
            riv_icon_imageview.setLayoutParams(layoutParams2);
        }
        return this;

    }

    //设置右边小图标的高
    public RounderAndCircleAvatarView setShowRightSmallIconHeight(int height) {
        if (riv_icon_imageview != null) {
            ViewGroup.LayoutParams layoutParams2 = riv_icon_imageview.getLayoutParams();
            layoutParams2.height = height;
            riv_icon_imageview.setLayoutParams(layoutParams2);
        }
        return this;

    }

    //头像内容到文本到顶部的距离
    public RounderAndCircleAvatarView setRightContentTopSize(int size) {
        if (tv_user_content != null) {
            LayoutParams layoutParams1 = (LayoutParams) tv_user_content.getLayoutParams();
            layoutParams1.topMargin = size;
            tv_user_content.setLayoutParams(layoutParams1);
            invalidate();
        }
        return this;

    }

    //设置右边文字的大小
    public RounderAndCircleAvatarView setRightContentSize(int size) {
        if (tv_user_content != null) {
            tv_user_content.setTextSize(size);
            invalidate();
        }
        return this;
    }

    //设置头像右边文本的内容
    public RounderAndCircleAvatarView setRightContentWord(String word) {
        if (tv_user_content != null) {
            tv_user_content.setText(word);
            invalidate();
        }
        return this;
    }

    //头像内容右边文本的颜色
    public RounderAndCircleAvatarView setRightContentColor(int color) {
        if (tv_user_content != null) {
            tv_user_content.setTextColor(color);
            invalidate();
        }
        return this;
    }

    //头像标题文本的大小
    public RounderAndCircleAvatarView setRightTitleSize(int size) {
        if (tv_user_title != null) {
            tv_user_title.setTextSize(size);
            invalidate();
        }
        return this;
    }

    //头像标题文本的内容
    public RounderAndCircleAvatarView setRightTitleWord(String content) {
        if (tv_user_title != null) {
            tv_user_title.setText(content);
            invalidate();
        }
        return this;
    }

    //头像标题文本颜色
    public RounderAndCircleAvatarView setRightTitleWordColor(int color) {
        if (tv_user_title != null) {
            tv_user_title.setTextColor(color);
            invalidate();
        }
        return this;
    }

    //方形圆角的大小
    public RounderAndCircleAvatarView setmAvaterRadius(int radius) {
        if (roundedImageView != null) {
            roundedImageView.setCornerRadius(radius);
            invalidate();
        }
        return this;

    }

    //设置底部字体的大小
    public RounderAndCircleAvatarView setAvaterTextBottomSize(int size) {
        if (tv_bottom_content != null) {
            tv_bottom_content.setTextSize(size);
            invalidate();
        }
        return this;
    }

    //设置头像底部字体的颜色
    public RounderAndCircleAvatarView setAvaterTextBottomColor(int color) {
        if (tv_bottom_content != null) {
            tv_bottom_content.setTextColor(color);
            invalidate();
        }
        return this;
    }

    //设置头像底部字体的名称
    public RounderAndCircleAvatarView setAvaterTextBottom(String content) {
        if (tv_bottom_content != null) {
            tv_bottom_content.setText(content);
            invalidate();
        }
        return this;

    }

    //设置中间文字的字体加粗
    public RounderAndCircleAvatarView setAvaterCenterBold(boolean isBold) {
        if (isBold) {
            tv_center_content.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        } else {
            tv_center_content.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        }
        return this;
    }

    //设置中间文字的大小
    public RounderAndCircleAvatarView setAvaterTextCenterSize(int size) {
        if (tv_center_content != null) {
            tv_center_content.setTextSize(size);
            invalidate();
        }
        return this;
    }

    //设置中间文字的颜色
    public RounderAndCircleAvatarView setAvaterTextCenterColor(int color) {
        if (tv_center_content != null) {
            tv_center_content.setTextColor(color);
            invalidate();
        }
        return this;
    }

    //设置边框中间的文字
    public RounderAndCircleAvatarView setAvaterTextCenter(String content) {
        if (tv_center_content != null) {
            tv_center_content.setText(content);
            invalidate();
        }
        return this;
    }

    //设置边框的宽度
    public RounderAndCircleAvatarView setmAvaterBorderWidth(int width) {
        if (roundedImageView != null) {
            roundedImageView.setBorderWidth(width);
            invalidate();
        }
        return this;
    }

    //设置变宽的颜色
    public RounderAndCircleAvatarView setAvaterBorderColor(int color) {
        if (roundedImageView != null) {
            roundedImageView.setBorderColor(color);
            invalidate();
        }
        return this;
    }

    //设置头像背景
    public RounderAndCircleAvatarView setmAvaterBackgroundColor(int color) {
        if (roundedImageView != null) {
            roundedImageView.setBackgroundColor(color);
            invalidate();
        }
        return this;
    }

    //设置是圆还是方
    public RounderAndCircleAvatarView setIsOver(boolean isOver) {
        if (roundedImageView != null) {
            roundedImageView.setOval(isOver);
            invalidate();
        }
        return this;

    }

    //设置图片的地址
    public RounderAndCircleAvatarView setAvatarSrc(int src) {
        if (roundedImageView != null) {
            roundedImageView.setImageResource(src);
            invalidate();
        }
        return this;
    }

    //设置图片头像的宽
    public RounderAndCircleAvatarView setmAvatarWidth(int width) {
        if (roundedImageView != null) {
            LayoutParams layoutParams = (LayoutParams) roundedImageView.getLayoutParams();
            layoutParams.width = width;
            roundedImageView.setLayoutParams(layoutParams);
            invalidate();
        }
        return this;
    }

    //设置图片头像的高
    public RounderAndCircleAvatarView setmAvatarHeight(int height) {
        if (roundedImageView != null) {
            LayoutParams layoutParams = (LayoutParams) roundedImageView.getLayoutParams();
            layoutParams.height = height;
            roundedImageView.setLayoutParams(layoutParams);
            invalidate();
        }
        return this;
    }

    public interface onClickListener {
        void onClickListener(int type, View view);
    }

    public void setOnClickListener(onClickListener listener) {
        this.listener = listener;
    }
}
